package test.com.flexoop.utilities.dateutils {

	import com.flexoop.utilities.dateutils.DateUtils;
	
	import org.flexunit.Assert;

	public class DateDiffTest {
		
		private var _startDate:Date;
		private var _endDate:Date;
		
		[Before]
		public function setUp():void {
			_startDate = new Date();
		}
		
		public function DateDiffTest() {
		}
		
		[Test]
		public function testYearDateDiff():void {
			_endDate = DateUtils.dateAdd( DateUtils.YEAR, 6, _startDate );
			Assert.assertEquals( "validate that adding 6 years works correctly", 6, DateUtils.dateDiff( DateUtils.YEAR, _startDate, _endDate ) );
			
			_endDate = DateUtils.dateAdd( DateUtils.YEAR, 1, _startDate );
			Assert.assertEquals( "validate that adding 1 year works correctly", 1, DateUtils.dateDiff( DateUtils.YEAR, _startDate, _endDate ) );

			_endDate = DateUtils.dateAdd( DateUtils.YEAR, -4, _startDate );
			Assert.assertEquals( "validate that subtracting 4 years works correctly", -4, DateUtils.dateDiff( DateUtils.YEAR, _startDate, _endDate ) );
		}
		
		[Test]
		public function testMonthDateDiff():void {
			_endDate = DateUtils.dateAdd( DateUtils.YEAR, 1, _startDate );
			_endDate = DateUtils.dateAdd( DateUtils.DAY_OF_MONTH, -1 , _endDate );
			
			Assert.assertEquals( "validate that adding 1 year and subtracting a day" + 
					"works correctly", 11, DateUtils.dateDiff( DateUtils.MONTH, _startDate, _endDate ) );

			_endDate = DateUtils.dateAdd( DateUtils.YEAR, 1, _endDate );
			Assert.assertEquals( "validate that adding 2 years and subtracting a day" + 
					"works correctly", 23, DateUtils.dateDiff( DateUtils.MONTH, _startDate, _endDate ) );

			_endDate = DateUtils.dateAdd( DateUtils.YEAR, 1, _endDate );
			Assert.assertEquals( "validate that adding 3 years and subtracting a day" + 
					"works correctly", 35, DateUtils.dateDiff( DateUtils.MONTH, _startDate, _endDate ) );
		}
		
		[After]
		public function tearDown():void {
			_startDate = null;
			_endDate = null;
		}

	}
}